var jqMyAjax = function(){ 
	var blockUi = new BlockUi();
	
	var blockUiSet = function(){
		var option = new Array();
		option["bgcolor"] = "gray";//string
		option["opacity"] = 0.2;//number
		option["animation"] = true;//boolean
		
		blockUi.block(option); 
	};

	var blockUiUnSet = function(){
		blockUi.unblock();	
	};

	var errorAjax = function(xhr, status, thrown){
		var code = xhr.status;
		var codeDesc = "";
		if(code == 401){ codeDesc = "[401 ERROR] UNAUTHORIZED / SESSION TIMEOUT";
		}else if(code == 403){ codeDesc = "[403 ERROR] FORBIDDEN";
		}else if(code == 404){ codeDesc = "[404 ERROR] NOT FOUND PAGE";
		}else if(code == 415){ codeDesc = "[415 ERROR] NOT SUPPORTED MEDIA FORMAT";
		}else if(code == 500){ codeDesc = "[500 ERROR] INTERNAL ERROR";
		}else if(code == 12029){ codeDesc = "[ERROR] NOT PERMITED TO ACCESS THE REMOTE SERVER";
		}else{ codeDesc = code + "[ERROR] UNKNOWN"; }

		blockUi.hideAnimation();
		alert(codeDesc);// +" : "+ xhr.getResponseHeader("errorMsg") +" : "+ thrown
		
		if(code == 401) window.top.location.href = "/";
	};

	var completeAjax = function(xhr, status){
		blockUiUnSet();
	};
	
	this.uiBlock = function(){
		blockUiSet();
	};
	
	this.uiUnBlock = function(){
		blockUiUnSet();
	};
	
	this.errorCalback = function(xhr, extraMsg, sessionOutRedirect){
		var code = xhr.status;
		var codeDesc = "";
		if(code == 401){ codeDesc = "[401 ERROR] UNAUTHORIZED / SESSION TIMEOUT";
		}else if(code == 403){ codeDesc = "[403 ERROR] FORBIDDEN";
		}else if(code == 404){ codeDesc = "[404 ERROR] NOT FOUND PAGE";
		}else if(code == 415){ codeDesc = "[415 ERROR] NOT SUPPORTED MEDIA FORMAT";
		}else if(code == 500){ codeDesc = "[500 ERROR] INTERNAL ERROR";
		}else if(code == 12029){ codeDesc = "[ERROR] NOT PERMITED TO ACCESS THE REMOTE SERVER";
		}else{ codeDesc = "["+code+" ERROR] UNKNOWN"; }

		blockUi.hideAnimation();

		alert(codeDesc + "\n\n" + extraMsg);
		
		if(code == 401 && sessionOutRedirect) {
			window.top.location.href = "/";
			return;
		}
		
		return codeDesc + "\n\n" + extraMsg;
	};
	
	this.callAjax = function(option){
		var type = !option.type ? "POST" : option.type;
		$.ajax({
			type:type
			,url:option.url
			,dataType:option.dataType
			,data:option.data
			,beforeSend:function(xhr){
				xhr.setRequestHeader("AJAX", true);
				
				if(option.contentType != null) {
					xhr.setRequestHeader("Content-Type", option.contentType);
				}
				
				blockUiSet();
			}
			,success:option.success
			,complete:(option.complete != null) ? option.complete : completeAjax
			,error:(option.error != null) ? option.error : errorAjax
		});
	};
	
	this.callAjaxJsonP = function(option){
		var type = !option.type ? "POST" : option.type;
		$.ajax({
			type:type
			,url:option.url
			,contentType : option.contentType
			,dataType:option.dataType
			,jsonp:"callback"//JSONP's options. you can change another one.
			,data:option.data
			,beforeSend:function(xhr){
				xhr.setRequestHeader("AJAX", true);
				
				//JSONP's options. you can change another one.
				xhr.setRequestHeader("Accept", "javascript/jsonp");

				blockUiSet();
			}
			,success:option.success
			,complete:(option.complete != null) ? option.complete : completeAjax
			,error:(option.error != null) ? option.error : errorAjax
		});
	};
	
	this.callAjaxFileUp = function(option){
		var type = !option.type ? "POST" : option.type;
		$.ajax({
			url:option.url
			,dataType:option.dataType
			,type:type
			,data:option.data
			,contentType : option.contentType
			,processData : option.processData		
			,beforeSend:function(xhr){
				blockUiSet();
			}
			,success:option.success
			,complete:(option.complete != null) ? option.complete : completeAjax
			,error:(option.error != null) ? option.error : errorAjax
		});
	};
	
	this.loadAjaxOpenApi = function(option){
		var type = !option.type ? "POST" : option.type;
		$.ajax({
			type:type
			,cache:option.cache
			,url:option.url
			,contentType : option.contentType
			,dataType:option.dataType
			,data:option.data
			,beforeSend:function(xhr){
				blockUiSet();
			}
			,success:option.success
			,complete:(option.complete != null) ? option.complete : completeAjax
			,error:(option.error != null) ? option.error : errorAjax
		});
	};
};
